App({
  globalData: {
    username:null,
    userWxId: "",
    user :{},
    reportArr: [] ,
    evaluateArr:[],
    loginFalg : false
  },

  connectsocket(user) {
    let that = this
    wx.connectSocket({
      //https://www.hankooktire-wx.com.cn:8443/htwx-api/
      url: 'wss://www.hankooktire-wx.com.cn:8443/htwx-api/websocket/{{userid:"' + user[0].wxId + '",softwaretype:' + "1" + '}}',
      //url: 'ws://115.231.73.155:8080/htwx-api/websocket/{{userid:"' + user[0].wxId + '",softwaretype:' + "1" + '}}',
      //url: 'ws://192.168.12.193:8080/websocket/{{userid:"' + user[0].wxId + '",softwaretype:' + "1" + '}}',
      header: { 'content-type': 'application/json' },
      method: 'GET',
      protocols: [],
      success: function (res) {
        console.log("创建成功!" , res)
      },
      fail: function (res) { },
      complete: function (res) { console.log("创建连接complete"); },
    })
    wx.onSocketOpen(function (res) {
      console.log('连接成功',res)
    })
  }
  ,
  sendWebsocket: function (user) {
    wx.sendSocketMessage({
      data: 
      "{'softwareType': 'User', 'instructions':'" + user[0].userContacts + "','content':'提交新的报修',socketId:'',instruct:''}",
      success: function (res) { console.log("发送成功") },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  onSocketMessage(page){
  wx.onSocketMessage(function (res) {
    console.log("开始接收")
    console.log("数据：", res)
    let ins = res.data.split(",");
    if (ins[1] == "processReport") {//处理报表
      console.log("processReport")
      wx.showToast({
        title: ins[0],
        icon: 'none',
        success: (res) => {
          page.onLoad();
        },
      })
    } else if (ins[1] == "deleteReport") {//删除记录
      console.log("deleteReport")
      wx.showToast({
        title: ins[0],
        icon: 'none',
        success: (res) => {
          page.onLoad();
        },
      })
    }else if (ins[1] == "reportFinish") {//报表维修完成
      console.log("reportFinish:报表维修完成")
      if (page.data.pageName == "mysubmit"){      
        wx.showToast({
          title: ins[0],
          icon: 'none',
          success: (res) => {
            page.onLoad();
          },
        })
      } else if (page.data.pageName == "information"){//更新没有评价的报修       
        wx.showToast({
          title: ins[0],
          icon: 'none',
          success: (res) => {
            page.getNotAppraised();
          },
        })
      }    
    } else if (ins[1] == "updateFactory") {//更新工厂信息
      console.log("updateFactory")
      wx.showToast({
        title: ins[0],
        icon: 'none',
        success: (res) => {         
          page.getFactroy();
        },
      })
    }
    
    

  })

  }
})